﻿package com.tudou.home.controller
{
    import com.tudou.ad.consts.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.controller.ad.*;
    import com.tudou.home.model.ad.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class PreCommand extends SimpleCommand
    {

        public function PreCommand()
        {
            return;
        }// end function

        private function removeAdFront() : void
        {
            facade.removeProxy(AdFrontProxy.NAME);
            facade.removeCommand(AdFrontCommandSet.START);
            facade.removeCommand(AdFrontCommandSet.CLEAR);
            facade.removeCommand(AdFrontCommandSet.PREPARE_TO_SHOW);
            facade.removeCommand(AdFrontCommandSet.ERROR_END);
            facade.removeCommand(AdFrontCommandSet.SHOW_START);
            facade.removeCommand(AdFrontCommandSet.SHOW_END);
            facade.removeCommand(AdFrontCommandSet.SHOW_NEAR_END);
            facade.removeCommand(AdFrontCommandSet.TIMEOUT_START_PLAY);
            return;
        }// end function

        private function registerAdFront() : void
        {
            facade.registerProxy(new AdFrontProxy());
            facade.registerCommand(AdFrontCommandSet.START, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.CLEAR, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.PREPARE_TO_SHOW, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.ERROR_END, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.SHOW_START, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.SHOW_END, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.SHOW_NEAR_END, AdFrontCommand);
            facade.registerCommand(AdFrontCommandSet.TIMEOUT_START_PLAY, AdFrontCommand);
            return;
        }// end function

        private function removeAdFrontLast() : void
        {
            facade.removeProxy(AdFrontLastProxy.NAME);
            facade.removeCommand(AdFrontLastCommandSet.START);
            facade.removeCommand(AdFrontLastCommandSet.CLEAR);
            facade.removeCommand(AdFrontLastCommandSet.PREPARE_TO_SHOW);
            facade.removeCommand(AdFrontLastCommandSet.ERROR_END);
            facade.removeCommand(AdFrontLastCommandSet.SHOW_START);
            facade.removeCommand(AdFrontLastCommandSet.SHOW_END);
            facade.removeCommand(AdFrontLastCommandSet.SHOW_NEAR_END);
            facade.removeCommand(AdFrontLastCommandSet.TIMEOUT_START_PLAY);
            return;
        }// end function

        private function registerAdFrontLast() : void
        {
            facade.registerProxy(new AdFrontLastProxy());
            facade.registerCommand(AdFrontLastCommandSet.START, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.CLEAR, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.PREPARE_TO_SHOW, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.ERROR_END, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.SHOW_START, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.SHOW_END, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.SHOW_NEAR_END, AdFrontLastCommand);
            facade.registerCommand(AdFrontLastCommandSet.TIMEOUT_START_PLAY, AdFrontLastCommand);
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            switch(param1.getName())
            {
                case ExternalCommandSet.ADD_AD_FRONT:
                {
                    registerAdFront();
                    break;
                }
                case ExternalCommandSet.REMOVE_AD_FRONT:
                {
                    removeAdFront();
                    break;
                }
                case ExternalCommandSet.ADD_AD_BACK:
                {
                    registerAdBack();
                    break;
                }
                case ExternalCommandSet.REMOVE_AD_BACK:
                {
                    removeAdBack();
                    break;
                }
                case ExternalCommandSet.ADD_AD_FRONT_LAST:
                {
                    registerAdFrontLast();
                    break;
                }
                case ExternalCommandSet.REMOVE_AD_FRONT_LAST:
                {
                    removeAdFrontLast();
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        private function registerAdBack() : void
        {
            facade.registerProxy(new AdBackProxy());
            facade.registerCommand(AdBackCommandSet.START, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.CLEAR, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.PREPARE_TO_SHOW, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.ERROR_END, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.SHOW_START, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.SHOW_END, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.SHOW_NEAR_END, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.TIMEOUT_START_PLAY, AdBackCommand);
            facade.registerCommand(AdBackCommandSet.START_PREPAREED, AdBackCommand);
            return;
        }// end function

        private function removeAdBack() : void
        {
            var _loc_1:* = facade.retrieveProxy(AdInfoProxy.NAME) as AdInfoProxy;
            _loc_1.removeAdItemByType(AdType.BACK);
            facade.removeProxy(AdBackProxy.NAME);
            facade.removeCommand(AdBackCommandSet.SHOW_START);
            facade.removeCommand(AdBackCommandSet.START);
            facade.removeCommand(AdBackCommandSet.CLEAR);
            facade.removeCommand(AdBackCommandSet.PREPARE_TO_SHOW);
            facade.removeCommand(AdBackCommandSet.ERROR_END);
            facade.removeCommand(AdBackCommandSet.SHOW_START);
            facade.removeCommand(AdBackCommandSet.SHOW_END);
            facade.removeCommand(AdBackCommandSet.SHOW_NEAR_END);
            facade.removeCommand(AdBackCommandSet.TIMEOUT_START_PLAY);
            facade.removeCommand(AdBackCommandSet.START_PREPAREED);
            return;
        }// end function

    }
}
